<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2018/8/20
 * Time: 11:49
 */

namespace app\admin\model;


use think\Model;

class ClassroomCatalogue extends Model
{
    /**
     * 获取当前课程下的所有章节
     * @param $mechanism_id
     * @param $page
     * @param $limit
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function catalogueLists($classroom_id, $page, $limit){
        $lists = $this->where('classroom_id', $classroom_id)
            ->order('catalogue_id')
            ->page($page, $limit)
            ->select();
        return $lists;
    }
    
    /**
     * 获取条件搜索的记录总数，用于分页
     * @param $where  搜索条件
     * @return int|string
     */
    public function getCount($classroom_id){
        $count = $this->where('classroom_id', $classroom_id)->count();
        return $count;
    }
    
    /**
     * 添加课程章节
     * @param $data
     * @return false|int
     */
    public function insertCatalogue($data){
        $res = $this->allowField(true)->save($data);
        return $res;
    }
}